const url = "http://192.168.6.62:3000/top/playlist"
Page({
    data:{
        musics:[]
    },
    onLoad(){
        wx.request({
            url: url,
            data: {
                cat:"华语",
                limit:15
            },
            method: 'GET', 
            success: res=>{
                let musics = res.data.playlists;
                this.setData({
                    musics:musics
                })
            }
        })
    },
    onReachBottom(){
        let offset  =  this.data.musics.length;
        let url = `http://192.168.6.62:3000/top/playlist?cat=华语&limit=15&offset=${offset}`;
        wx.showNavigationBarLoading()
        wx.request({
            url: url,
            method: 'GET', 
            success: res=>{
                //又获取15条数据,需要它们添加到musics中
                let result = res.data.playlists;
                let musics = this.data.musics;
                console.log(result)
                let total = musics.concat(result);
                this.setData({
                    musics:total
                })
                wx.hideNavigationBarLoading()
            }
        })
        
    },
    handleClick(event){
        let id = event.currentTarget.dataset.id;
        wx.navigateTo({
            url: `/pages/detail/detail?id=${id}`
        })
    }
})
